package com.feihong.txgw.tx_precenter;

import com.feihong.txgw.inter.contract.adr.IDeliveryAdrContract;
import com.feihong.txgw.model.base_bean.BaseResponse;
import com.feihong.txgw.tx_model.DeliveryAdrMainModel;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName DeliveryAdrMainPrecenter
 * @package com.feihong.txgw.tx_precenter
 * @data 2018/5/7 19:27
 * @Describe
 * @Change
 */
public class DeliveryAdrMainPrecenter extends IDeliveryAdrContract.AbDeliveryAdrMainPrecenter {

    public static DeliveryAdrMainPrecenter create(){
        return new DeliveryAdrMainPrecenter();
    }

    @Override
    public void getDeliveryAdrInfo() {
        mIModel.getDeliveryAdrInfo().subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mRxManager.register(d);
            }

            @Override
            public void onNext(String s) {
                mIView.getDeliveryAdrInfoResult(s);
            }

            @Override
            public void onError(Throwable e) {
                mIView.getDeliveryAdrInfoError();
            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public void delDeliveryAdr(String adrID) {
        mIModel.delDeliveryAdr(adrID).subscribe(new Observer<BaseResponse>() {
            @Override
            public void onSubscribe(Disposable d) {
                mRxManager.register(d);
            }

            @Override
            public void onNext(BaseResponse s) {
                mIView.delDeliveryAdrResult(s);
            }

            @Override
            public void onError(Throwable e) {
                mIView.delDeliveryAdrError();
            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public IDeliveryAdrContract.IDeliveryAdrMainModel getModel() {
        return DeliveryAdrMainModel.create();
    }

    @Override
    public void onStart() {

    }
}
